

function tick(updater: () => void, updateTime?: number, updateCondition?: () => boolean) {
    let lastTime = Date.now();

    return function () {
        if (updateTime) {
            const timer = setInterval(() => {
                if (updateCondition && updateCondition()) {
                    if (Date.now() - lastTime > updateTime) {
                        clearInterval(timer)
                        window.requestAnimationFrame(updater);
                        lastTime = Date.now()

                    }
                } else {
                    if (Date.now() - lastTime > updateTime) {
                        clearInterval(timer)
                        window.requestAnimationFrame(updater);
                        lastTime = Date.now()
                    }
                }
            }, 16)
        } else {
            window.requestAnimationFrame(updater);
        }
    }

}

export default tick;